﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Medianamik.Core
{
    public abstract class SubEntity<TEntityType, TOwnerType> : Entity<TEntityType>
        where TEntityType : IEntity
        where TOwnerType : IEntity
    {
        protected SubEntity()
        {
            
        }

        protected SubEntity(Guid id)
            : base(id)
        {

        }

        private TOwnerType _owner;
        public TOwnerType Owner
        { 
            get
            {
                if (_owner == null)
                {
                    _owner = GetOwner(OwnerId);
                }

                return _owner;
            }
            internal set
            {
                _owner = value;
                OwnerId = value.ID;
            }
        }

        protected abstract TOwnerType GetOwner(Guid ownerId);

        public Guid OwnerId { get; internal set; }
    }
}
